package xstream;

import org.eclipse.recommenders.snipmatch.core.Effect;
import org.eclipse.recommenders.snipmatch.core.EffectMatchNode;
import org.eclipse.recommenders.snipmatch.core.EffectParameter;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver;
import com.thoughtworks.xstream.io.xml.DomDriver;

public class main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		
		/*String xml = "<person><firstname>Joe</firstname><lastname>Walnes</lastname><phone><code>123</code><number>1234-456</number></phone> <fax><code>123</code><number>9999-999</number></fax></person>";
		// TODO Auto-generated method stub
		getOBjectFromXML(xml);*/
		
		XStream xstream = new XStream(new JettisonMappedXmlDriver());
		xstream.alias("param", EffectParameter.class);
		xstream.alias("effect", Effect.class);
		EffectParameter param = new EffectParameter();
		param.setName("obj");
		param.setMajorType("expr:");
		
		Effect effect = new Effect();
		effect.setCode("System.out.print(${obj});");
		effect.setSummary("Print to standard output.");
		effect.setEnvironmentName("javasnippet");
		effect.setMajorType("stmt");
		effect.addPattern("print $obj");
		effect.addParameter(param);
		
		String xml = xstream.toXML(effect);

        System.out.println(xml);
	}
	
	
	
	
	public static void createXML(){
		XStream xstream = new XStream(new DomDriver());
		xstream.alias("person", Person.class);
		xstream.alias("phonenumber", PhoneNumber.class);
		Person joe = new Person("Joe", "Walnes");
		joe.setPhone(new PhoneNumber(123, "1234-456"));
		joe.setFax(new PhoneNumber(123, "9999-999"));
		String xml = xstream.toXML(joe);
		
		System.out.println(xml);
	}
	
	public static void createJSON(){
		XStream xstream = new XStream(new JettisonMappedXmlDriver());
        xstream.alias("person", Person.class);
		xstream.alias("phonenumber", PhoneNumber.class);
		Person joe = new Person("Joe", "Walnes");
		joe.setPhone(new PhoneNumber(123, "1234-456"));
		joe.setFax(new PhoneNumber(123, "9999-999"));
		String xml = xstream.toXML(joe);

        System.out.println(xml);
	}

	public static void getOBjectFromXML(String xml){
		XStream xstream = new XStream(new DomDriver());
		xstream.alias("person", Person.class);
		xstream.alias("phonenumber", PhoneNumber.class);
		Person newJoe = (Person)xstream.fromXML(xml);
		System.out.println(newJoe.getFirstname());
	}
}
